<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="paryorder-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="false">
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="list-item" v-for="(item, index) in dataList" :key="index" @click="$mRouter.push({ route: '/pages/purchase/shouhou/xiangqing?id=' + item.id })">
				<view class="item-header">
					<view class="left">
						{{ item.approverShopName }}
					</view>
					<view class="right">
						<text :style="{fontSize: '26rpx', color: badgeColor}">{{item.statusDescription}}</text>
					</view>
				</view>
				<view class="item-content" v-for="info in item.items" :key="info.itemId">
					<img :src="info.itemResourceUrl" alt="" style="width: 180rpx;height:180rpx;border-radius: 10rpx;">
					<view class="u-flex-col u-row-around u-m-l-20" style="flex-grow: 1;">
						<view>{{ info.itemName }}</view>
						<view class="u-flex u-row-between">
							<view class="u-flex u-row-left">
								<view class="grey-box">
									{{ info.specification }}
								</view>
							</view>
							<view class="u-font-32">
								￥{{ info.unitPrice }}
							</view>
						</view>
						<view class="u-flex u-row-right">
							<view  class="grey-box">
								x{{ info.quantity }}
							</view>
						</view>
					</view>
				</view>
				<view class="u-flex u-row-between" >
					<view class="u-flex u-row-between">
						<view v-if="item.afterSalesType == 1" class="u-font-24 theme-color theme-box">
							退款
						</view>
						<view v-else class="u-font-24 theme-color theme-box">
							退货
						</view>
					</view>
					<view class="u-text-right">
						<!-- <text :style="{fontSize: '32rpx', color: greyColor}">总价￥4300.00</text> -->
						<text class="u-font-28">退款额 <text class="u-font-36 badge-color">￥{{ item.amount }}</text></text>
					</view>
				</view>
				<hr style="margin-top: 30rpx;opacity: 0.1;" />
				<view class="item-footer">
					<view  class="u-font-24 grey-color">售后单号：{{ item.serialNo }}</view>
					<view  class="u-font-24 grey-color">订单号：{{ item.tradeNo }}</view>
				</view>
			</view>
		</z-paging>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				firstLoaded: false,
				paymentStatus:['待审核','生效中','已拒绝','已过期','草稿','保存']
			}
		},
		props:{
			//当前组件的index，也就是当前组件是swiper中的第几个
			tabIndex: {
				type: Number,
				default: function(){
					return 0
				}
			},
			//当前swiper切换到第几个index
			currentIndex: {
				type: Number,
				default: function(){
					return 0
				}
			},
			value:{
				type: Number,
				default: function(){
					return 0
				}
			},
			keyWords:{
				type: String,
				default: function(){
					return ''
				}
			},
			filterData:{
				type:Object,
				default:function(){
					return {
						startTime:'',
						endTime:'',
						orderNo:'',
						saleShopName:'',
					}
				}
			},
			reload:{
				type: Boolean,
				default: function(){
					return false
				}
			}
			
		},
		watch: {
			currentIndex: {
				handler(newVal) {
					if(newVal === this.tabIndex){
						//懒加载，当滑动到当前的item时，才去加载
						if(this.reload||!this.firstLoaded){
							setTimeout(() => {
								this.$refs.paging.reload();
							}, 100);
						}
					}
				},
				immediate: true
			},
			filterData: {
				handler(newVal) {
					if(this.reload){
						setTimeout(() => {
							this.$refs.paging.reload();
						}, 100);
					}
				},
				deep:true,
				immediate: true
			},
			keyWords:{
				handler(newVal) {
					//懒加载，当滑动到当前的item时，才去加载
					setTimeout(() => {
						this.$refs.paging.reload();
					}, 100);
				},
			}
		},
		methods: {
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
				}
				if(this.value != 99){
					params.status = this.value;
				}
				if(this.keyWords!==''){
					params.ItemName = this.keyWords;
				}
				if(this.filterData.orderNo!==''){
					params.TradeNo = this.filterData.orderNo;
				}
				if(this.filterData.saleShopName!==''){
					params.ApproverShopName = this.filterData.saleShopName;
				}
				if(this.filterData.startTime!==''){
					params.startTime = this.filterData.startTime;
				}
				if(this.filterData.endTime!==''){
					params.EndTime = this.filterData.endTime;
				}
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/v1.3/AfterSalesOrder/GetApplicantASOByPage', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
					this.firstLoaded = true;
					
				}else{
					this.$refs.paging.complete(false);
				}
			},
			itemClick(item) {
				if(item.paymentStatus != 5){
					this.$mRouter.push({
						route: '/pages/purchase/mySale/signDetails?data='+JSON.stringify(item),
					})
				}else{
					this.$u.toast('该付款单已关闭')
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
	}
	.list-item {
		background-color: #FFFFFF;
		padding: 0 35rpx;
		margin-bottom: 20rpx;
		.theme-box {
			border: 1rpx solid $theme-color;
			padding: 5rpx 16rpx;
			border-radius: 5rpx;
		}
		.item-header {
			display: flex;
			justify-content: space-between;
			font-size: 24rpx;
			font-weight: bold;
			line-height: 81rpx;
			height: 81rpx;
			.left {
				font-size: 30rpx;
			}
			.right {
				font-size: 26rpx;
				color: $theme-color;
			}
		}
		.item-content {
			display: flex;
			justify-content: flex-start;
			margin-bottom: 30rpx;
			.center {
				margin-left: 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
			}
		}
		.item-footer {
			padding: 20rpx 0;
			min-height: 110rpx;
		}
	}


</style>
